package com.yeyks.config.service.impl;

import com.yeyks.common.base.PageInfo;
import com.yeyks.config.dal.domain.DocInfo;
import com.yeyks.config.dal.dao.DocInfoMapper;
import com.yeyks.config.service.DocInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 文档表 服务实现类
 * </p>
 *
 * @author yun
 * @since 2019-06-25
 */
@Service
public class DocInfoServiceImpl extends ServiceImpl<DocInfoMapper, DocInfo> implements DocInfoService {

    /**
     * 获取文档列表
     *
     * @param parent
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Map<String, Object> selectDocByPage(Integer parent, String keyword, Integer pageNum, Integer pageSize) {
        PageInfo pageInfo = PageInfo.of(pageNum, pageSize);
        List<Map> docInfoList;
        int count;
        //分类
        if (parent == 1) {
            docInfoList = baseMapper.selectByDirectorKeyword(true, keyword, pageInfo.getOffset(), pageInfo.getLimit());
            count = baseMapper.selectByDirectorKeywordCount(true, keyword);

        } else if (parent == 0) {//内容
            docInfoList = baseMapper.selectByDirectorKeyword(false, keyword, pageInfo.getOffset(), pageInfo.getLimit());
            count = baseMapper.selectByDirectorKeywordCount(false, keyword);
        } else {
            docInfoList = baseMapper.selectByParentKeyword(parent, keyword, pageInfo.getOffset(), pageInfo.getLimit());
            count = baseMapper.selectByParentKeywordCount(parent, keyword);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("list", docInfoList);
        map.put("count", count);
        return map;
    }

}
